package log

import (
	"encoding/json"
	"fmt"
	log "github.com/sirupsen/logrus"
)

type MyJSONFormatter struct {
}

func (f *MyJSONFormatter) Format(entry *log.Entry) ([]byte, error) {
	serialized, err := json.Marshal(entry)
	if err != nil {
		return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err)
	}
	return append(serialized, '\n'), nil
}

func FomatDemo() {
	log.SetFormatter(new(MyJSONFormatter))
	log.WithFields(log.Fields{"1": "name", "2": "add"}).Warn("msg", "event")
	log.WithFields(log.Fields{
		"animal": "walrus",
		"size":   10,
	}).Info("A group of walrus emerges from the ocean")

}
